package enumTest;

/**
 * 自定义 index
 */
public class EnumCuttomOrdinal {
	public static void main(String[] args) {

		//true 
		System.out.println("EnumCuttomOrdinal:main:"+(MyColor.RED == MyColor.RED));


		MyColor c1=MyColor.RED;
		MyColor c2=MyColor.RED;
		System.out.println("c1==c2=="+(c1==c2));//true
		System.out.println("c1.equals(c2)=="+(c1.equals(c2)));//true
			System.out.println(MyColor.RED);
			switch (MyColor.RED) {
			case RED:
				System.out.println("Red");
				break;

			default:
				System.out.println("de");
				break;
			}
			for (int i = 0; i < 4; i++) {
				System.out.println("---"+MyColor.getName(i));
			}
	}
}

//默认从 0 开始。
enum MyColor {
	   RED("红色", 1), GREEN("绿色", 2), BLANK("白色", 3), YELLO("黄色", 4);  
	    // 成员变量  
	    private String name;  
	    private int index;  
	    // 构造方法  
	    private MyColor(String name, int index) {  
	        this.name = name;  
	        this.index = index;  
	    }  
	    // 普通方法  
	    public static String getName(int index) {  
	        for (MyColor c : MyColor.values()) {  
	            if (c.getIndex() == index) {  
	                return c.name;  
	            }  
	        }  
	        return null;  
	    }  
	    // get set 方法  
	    public String getName() {  
	        return name;  
	    }  
	    public void setName(String name) {  
	        this.name = name;  
	    }  
	    public int getIndex() {  
	        return index;  
	    }  
	    public void setIndex(int index) {  
	        this.index = index;  
	    }  
}